/*
 * @Autor: dingxiaolin
 * @Date: 2020-12-29 17:03:07
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2020-12-30 00:15:55
 */
var http=require( 'http' );
var requestpromise = require('request-promise');
var md5=require( 'md5' );
var qr = require('qr-image');
const {appid} = require('../../src/manifest.json')["mp-weixin"]
const {pages} = require('../../src/pages.json')
const url=`https://open.weixin.qq.com/sns/getexpappinfo?appid=${appid}&path=${pages[0].path}.html`
const png = qr.imageSync(url, { type: 'png' });
const base64Data=Buffer(png).toString('base64')
var qrbody={
    "msgtype": "image",
    "image": {
        "base64": base64Data,
        "md5": md5(Buffer(png))
    }
}
function noticebody(content){
   return {
    "msgtype": "text",
    "text": {
      "content": content
    }
  }
}
function options(body) {
    return {
        method: 'POST',
        url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7dbe9c6d-3d12-4687-9132-142717d4dc7e',
        body:body,
        json: true
    }
};
function noticeSucc(content){
    requestpromise(options(noticebody(content))).then(res=>{
        requestpromise(options(qrbody))
    }).catch(rej=>{
        console.log("rej",rej);
    })
}
function noticeFail(){
    requestpromise(options(noticebody(content))).then(res=>{
    }).catch(rej=>{
        console.log("rej",rej);
    })
}

module.exports={
    noticeSucc,noticeFail
}
